// This file replicates Figure 1 and Table A4

clear
// Download the Democrat Committee Requests data
use SenateDemocratCommitteeRequests.dta


**************
** Figure 1 **
**************

// Generate an indicator variable for being a Freshman
gen Freshman = 1 if chambsen == 1
replace Freshman = 0 if chambsen != 1

// Counts number of Constituency Committees Requested in 1st Request
// Note Constituency committees are 1) Small Business, 2) Veterans Affairs, 3) Agriculture, Nutrition and Forestry, 4) Armed Services, 5) Energy and Natural Resources

gen ConstituencyReq1 = 1 if commreq1 == "Small Business" | commreq1 == "Veterans Affairs" | commreq1 == "Agriculture, Nutrition and Forestry" | commreq1 == "Armed Services" | commreq1 == "Energy and Natural Resources"

// Counts number of Policy Committees Requested in 1st Request
// Note Policy committees are 1) Banking, Housing, and Urban Affairs, 2) Commerce, Science and Transportation, 3) Environment and Public Works, 4) Finance, 5) Foreign Relations, 6) Government Affairs, 7) Judiciary, 8) Labor and Human Resources

bysort Freshman: summarize ConstituencyReq1

gen PolicyReq1 = 1 if commreq1 == "Banking, Housing, and Urban Affairs" | commreq1 == "Commerce, Science and Transportation" | commreq1 == "Environment and Public Works" | commreq1 == "Finance" | commreq1 == "Foreign Relations" | commreq1 == "Government Affairs" | commreq1 == "Judiciary" | commreq1 == "Labor and Human Resources"

bysort Freshman: summarize PolicyReq1


// Counts number of Prestige Committees Requested in 1st Request
// Note Constituency committees are 1) Appropriations, 2) Budget, 3) Rules and Administration

gen PrestigeReq1 = 1 if commreq1 == "Appropriations" | commreq1 == "Budget" | commreq1 == "Rules and Administration"

bysort Freshman: summarize PrestigeReq1


// Counts number of Admin Committees Requested in 1st Request
// Note Constituency committees are 1) District of Columbia, 2) Post Office
gen AdminReq1 = 1 if commreq1 == "District of Columbia" | commreq1 == "Post Office" 

bysort Freshman: summarize AdminReq1



// Now we can create a pie-chart for the category of committee requested as first choice by Freshman
* Calculate sums for the subset where Freshman == 1
summarize PrestigeReq1 if Freshman == 1
gen sum_prestige_f = r(sum)

summarize ConstituencyReq1 if Freshman == 1
gen sum_constituency_f = r(sum)

summarize AdminReq1 if Freshman == 1
gen sum_admin_f = r(sum)

summarize PolicyReq1 if Freshman == 1
gen sum_policy_f = r(sum)


graph pie sum_prestige_f sum_constituency_f sum_admin_f sum_policy_f

* Save graph of Figure 1 for Freshmen
graph save Figure1_Freshmen



scalar Freshman_Prestige_Req1 = sum_prestige_f /(sum_prestige_f + sum_constituency_f + sum_admin_f + sum_policy_f)
display Freshman_Prestige_Req1


scalar Freshman_Admin_Req1 = sum_admin_f /(sum_prestige_f + sum_constituency_f + sum_admin_f + sum_policy_f)
display Freshman_Admin_Req1


scalar Freshman_Constituency_Req1 = sum_constituency_f /(sum_prestige_f + sum_constituency_f + sum_admin_f + sum_policy_f)
display  Freshman_Constituency_Req1 


scalar Freshman_Policy_Req1 = sum_policy_f /(sum_prestige_f + sum_constituency_f + sum_admin_f + sum_policy_f)
display Freshman_Policy_Req1



// Now we can create a pie-chart for the category of committee requested as first choice by Non-Freshman
* Calculate sums for the subset where Freshman == 0
summarize PrestigeReq1 if Freshman == 0
gen sum_prestige_nf = r(sum)

summarize ConstituencyReq1 if Freshman == 0
gen sum_constituency_nf = r(sum)

summarize AdminReq1 if Freshman == 0
gen sum_admin_nf = r(sum)

summarize PolicyReq1 if Freshman == 0
gen sum_policy_nf = r(sum)


graph pie sum_prestige_nf sum_constituency_nf sum_admin_nf sum_policy_nf

* Save graph of Figure 1 for Non-Freshmen
graph save Figure1_NonFreshmen

scalar NonFreshman_Prestige_Req1 = sum_prestige_nf /(sum_prestige_nf + sum_constituency_nf + sum_admin_nf + sum_policy_nf)
display NonFreshman_Prestige_Req1


scalar NonFreshman_Admin_Req1 = sum_admin_nf /(sum_prestige_nf + sum_constituency_nf + sum_admin_nf + sum_policy_nf)
display NonFreshman_Admin_Req1


scalar NonFreshman_Constituency_Req1 = sum_constituency_nf /(sum_prestige_nf + sum_constituency_nf + sum_admin_nf + sum_policy_nf)
display  NonFreshman_Constituency_Req1 


scalar NonFreshman_Policy_Req1 = sum_policy_nf /(sum_prestige_nf + sum_constituency_nf + sum_admin_nf + sum_policy_nf)
display NonFreshman_Policy_Req1

**************
** Table A4 **
**************

** Constituency Committees
summarize chambsen if  ifrequestedsmallbuss ==1 
scalar avg_sen_smallbusiness = r(mean)
display avg_sen_smallbusiness

summarize chambsen if  ifrequstedveter ==1 
scalar avg_sen_veteransaffair = r(mean)
display avg_sen_veteransaffair

summarize chambsen if  ifrequestedagri ==1 
scalar avg_sen_agriculture = r(mean)
display avg_sen_agriculture

summarize chambsen if  ifreqarmed ==1 
scalar avg_sen_armedserv = r(mean)
display avg_sen_armedserv

summarize chambsen if  ifreqenergy ==1 
scalar avg_sen_energy = r(mean)
display avg_sen_energy


scalar avg_constituency = (avg_sen_energy + avg_sen_armedserv + avg_sen_agriculture + avg_sen_veteransaffair + avg_sen_smallbusiness)/5
display avg_constituency


** Policy Committees
summarize chambsen if  ifreqbanking ==1 
scalar avg_sen_banking = r(mean)
display avg_sen_banking

summarize chambsen if  ifreqcommerce ==1 
scalar avg_sen_commerce = r(mean)
display avg_sen_commerce

summarize chambsen if  ifreqenviron ==1 
scalar avg_sen_environment = r(mean)
display avg_sen_environment

summarize chambsen if  ifreqfinan ==1 
scalar avg_sen_finance = r(mean)
display avg_sen_finance

summarize chambsen if  ifreqforaff ==1 
scalar avg_sen_foreignaffairs = r(mean)
display avg_sen_foreignaffairs

summarize chambsen if  ifreqgovtaff ==1 
scalar avg_sen_govtaffairs = r(mean)
display avg_sen_govtaffairs

summarize chambsen if  ifreqjudi ==1 
scalar avg_sen_judiciary = r(mean)
display avg_sen_judiciary

summarize chambsen if  ifreqlabor ==1 
scalar avg_sen_labor = r(mean)
display avg_sen_labor


scalar avg_policy = (avg_sen_banking + avg_sen_commerce + avg_sen_environment + avg_sen_finance + avg_sen_foreignaffairs + avg_sen_govtaffairs + avg_sen_judiciary + avg_sen_labor)/8
display avg_policy


** Prestige Committees

summarize chambsen if  ifreqappro ==1 
scalar avg_sen_appropriations = r(mean)
display avg_sen_appropriations

summarize chambsen if  ifreqbudget ==1 
scalar avg_sen_budget= r(mean)
display avg_sen_budget

summarize chambsen if  ifreqrules ==1 
scalar avg_sen_rules = r(mean)
display avg_sen_rules


scalar avg_prestige = (avg_sen_appropriations + avg_sen_budget + avg_sen_rules)/3
display avg_prestige



** Admin Committees

summarize chambsen if  ifreqdistric ==1 
scalar avg_sen_districtofcolumbia = r(mean)
display avg_sen_districtofcolumbia

summarize chambsen if  ifreqpost ==1 
scalar avg_sen_post= r(mean)
display avg_sen_post


scalar avg_admin = (avg_sen_districtofcolumbia+avg_sen_post)/2
display avg_admin


matrix TableA4 =avg_sen_smallbusiness\avg_sen_veteransaffair\avg_sen_agriculture\avg_sen_armedserv\avg_sen_energy\avg_constituency\avg_sen_banking\avg_sen_commerce\avg_sen_environment\avg_sen_finance\avg_sen_foreignaffairs\avg_sen_govtaffairs\avg_sen_judiciary\avg_sen_labor\avg_policy\avg_sen_appropriations\avg_sen_budget\avg_sen_rules\avg_prestige\avg_sen_districtofcolumbia \avg_sen_post \avg_admin

esttab matrix(TableA4) using TableA4

          